<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/8/18 10:22
 * Modified Time: 2019/8/18 10:22
 * Version: 2.0
 */

namespace App\Modules\Activity\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class ActivityDetailsCriteria extends BaseCriterias
{
    protected $activity_id;
    public function __construct($activity_id)
    {
        $this->activity_id = $activity_id;
    }

    public function apply($model, RepositoryInterface $repository)
    {
        $activity_id = $this->activity_id;

        $select = [
            'hx_store_activity.id',
            'title',
            'content',
            'expire',
            'IF(expire>NOW(),0,1) as is_expired',
            'hx_store.id as store_id',
            'hx_store.name',
            'hx_store_activity.created_at',
            'hx_picture.image as playbill'
        ];
        $select = implode($select,',');
        return $model->selectRaw($select)
            ->leftJoin('picture','store_activity.playbill','picture.id')
            ->leftJoin('store','store_activity.store_id','store.id')
            ->where('store_activity.id',$activity_id)
            ;
    }
}